﻿using Hvam.SharePoint.Search.Query.Site.Models;

namespace Hvam.SharePoint.Search.Query.Site.ResultSteps
{
    internal class SiteTitleResultStep : SiteSearchResultStep
    {
        public SiteTitleResultStep(SiteSearchQuery query)
            : base(query)
        {
            
        }

        public override SiteSearchResult Process(SiteSearchResult result)
        {
            if (Query.RequestedProperties.Contains("sitetitle") &&
                !result.Properties.ContainsKey("sitetitle"))
            {
                var item = result.ListItem;

                var web = item.Web;

                result.Properties.Add("sitetitle", web.Title);
            }
            return result;
        }
    }
}
